package screen.component
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	
	import helper.ValueObject;

	/**
	 * ...
	 * @author ...
	 */
	public class Guide extends UI
	{
		private const TUTO_NO:Number = 4;
		private const THELE_NO:Number = 6;
		private var _guide_popup:MovieClip; 
		private var _thele_popup:MovieClip;
		private const _TUTORIAL_AVATAR_FOLDER:String = "../assets/tutorial/";
		private const _THELE_AVATAR_FOLDER:String = "../assets/thele/";
		private const _TUTORIAL_UNIT_WIDTH:Number = 610;
		private var _tutorial_group:MovieClip;
		private var _thele_group:MovieClip;
		static private var instance:Guide;
		
		public function Guide() 
		{
			if(!instance){
				instance = this;
			}			
			init();
		}
		public static function getInstance(): Guide{
			if(!instance){
				instance = new Guide();
			}
			return instance;
		}
		public function init():void {
			_guide_popup = ValueObject.S2_RESOURCE.getExportedAsset("guidePopup") as MovieClip;
			popupInit(_guide_popup);
			_tutorial_group = new MovieClip;
			_guide_popup.addChild(_tutorial_group);
			with(_guide_popup){
				_tutorial_group.x = maskMc.x;
				_tutorial_group.y = maskMc.y;
				_tutorial_group.mask = maskMc;
				sliderInit(_tutorial_group,1,1,_tutorial_group.x,_TUTORIAL_UNIT_WIDTH);
				buttonImageInit(nextBtn);
				MovieClip(nextBtn).addEventListener(MouseEvent.CLICK,nextTutoHandle);
				buttonImageInit(preBtn);
				MovieClip(preBtn).addEventListener(MouseEvent.CLICK,preTutoHandle);
				buttonImageInit(closeBtn);
				MovieClip(closeBtn).addEventListener(MouseEvent.CLICK,hideGuidePopup)
			}
			for(var i:Number=1;i<=TUTO_NO;i++){
				var tutorial_unit:MovieClip = ValueObject.S2_RESOURCE.getExportedAsset("tutorialUnit") as MovieClip;
				tutorial_unit.avatar.load(new URLRequest(_TUTORIAL_AVATAR_FOLDER + "guide" + i + ".png"));
				tutorial_unit.x = (i-1)*_TUTORIAL_UNIT_WIDTH;
				_tutorial_group.addChild(tutorial_unit);
			}
			updateSliderBtn(_tutorial_group);
			
			_thele_popup = ValueObject.S2_RESOURCE.getExportedAsset("thelePopup") as MovieClip;
			popupInit(_thele_popup);
			_thele_group = new MovieClip;
			_thele_popup.addChild(_thele_group);
			with(_thele_popup){
				_thele_group.x = maskMc.x;
				_thele_group.y = maskMc.y;
				_thele_group.mask = maskMc;
				sliderInit(_thele_group,1,1,_thele_group.x,_TUTORIAL_UNIT_WIDTH);
				buttonImageInit(nextBtn);
				MovieClip(nextBtn).addEventListener(MouseEvent.CLICK,nextTheleHandle);
				buttonImageInit(preBtn);
				MovieClip(preBtn).addEventListener(MouseEvent.CLICK,preTheleHandle);
				buttonImageInit(closeBtn);
				MovieClip(closeBtn).addEventListener(MouseEvent.CLICK,hideThelePopup)
			}
			for(var j:Number=1;j<=THELE_NO;j++){
				var thele_unit:MovieClip = ValueObject.S2_RESOURCE.getExportedAsset("theleUnit") as MovieClip;
				thele_unit.avatar.load(new URLRequest(_THELE_AVATAR_FOLDER + j + ".png"));
				thele_unit.x = (j-1)*_TUTORIAL_UNIT_WIDTH;
				_thele_group.addChild(thele_unit);
			}
			updateSliderBtn(_thele_group);			
			
		}
		private function nextTutoHandle(e:MouseEvent):void{
			sliderNextClick(_tutorial_group);
		}
		private function preTutoHandle(e:MouseEvent):void{
			sliderPreClick(_tutorial_group);
		}
		private function nextTheleHandle(e:MouseEvent):void{
			sliderNextClick(_thele_group);
		}
		private function preTheleHandle(e:MouseEvent):void{
			sliderPreClick(_thele_group);
		}
		public function showGuidePopup():void {
			popupShow(_guide_popup);
		}
		public function showThelePopup():void {
			popupShow(_thele_popup);
		}
		public function hideGuidePopup(e:MouseEvent=null):void {
			popupHide(_guide_popup);
		}
		public function hideThelePopup(e:MouseEvent=null):void {
			popupHide(_thele_popup);
		}
	}

}